package com.dy.分类.栈队列堆.合法的出栈序列;

import java.util.Stack;

public class Solution {
    public boolean IsPopOrder(int[] pushA, int[] popA) {
        Stack<Integer> stack = new Stack<>();
        int pushi = 0;
        int popi = 0;
        while (pushi < pushA.length) {

            stack.push(pushA[pushi]);
            while (!stack.isEmpty() && popA[popi] == stack.peek()) {
                stack.pop();
                popi++;
            }
            pushi++;

        }
        return stack.isEmpty();
    }
}
